<template>
  <div style="height: 100%">
    <el-container style="min-height: 100vh;">
      <!-- header部分 -->
      <el-header>
        <navtop :user="user"></navtop>
      </el-header>
      <el-container>
        <!-- aside部分 -->
        <leftNav></leftNav>
        <el-main>
          <!-- main部分 -->
          <router-view @refreshUser="getUser" />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import navtop from "../components/Nav-top";
import leftNav from "../components/Nav";

export default {
  name: "Doctor",
  data() {
    return {
      activeIndex: '1',
      user: localStorage.getItem("phy") ? JSON.parse(localStorage.getItem("phy")) : {},
      isCollapse: false,
      sideWidth: 220,
    };
  },
  components: {
    navtop,
    leftNav
  },
  created() {
    this.getUser()
  },
  methods: {
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    },
    logout(){
      this.request.delete("/physician/token?token="+localStorage.getItem("token")).then(res=>{
        localStorage.removeItem("phy")
        this.$router.push("/login")
      })
      this.$message.success("退出成功")
    },
    //获取用户的最新数据
    getUser(){
      let role = localStorage.getItem("phy") ? JSON.parse(localStorage.getItem("phy")).roleId : 0
      let username = localStorage.getItem("phy") ? JSON.parse(localStorage.getItem("phy")).username : ""
      this.request.post("/physician/findByName?username=" + username).then(res => {
        if (res) {
          res.token = this.user.token
          console.log(res)
          this.user = res
          localStorage.setItem("phy",JSON.stringify(this.user))
        }
      })
    }
  }
}
</script>

<style>
.el-main {
  background-color: #f5f7f9;
}

.el-header,
.el-footer {
  background-color: white;
  box-sizing: border-box;
  border-bottom: 1px solid #f5f1f1;
}

.el-container {
  height: 100%;
}
</style>
